package org.example.zcn2022.controll;

import com.alibaba.fastjson.JSONObject;
import org.example.zcn2022.entity.ZcnStaff;
import org.example.zcn2022.service.ZcnStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class StaffControll {
    @Autowired
    public ZcnStaffService zcnStaffService;

    @ResponseBody
    @RequestMapping(value = "/getStaffs", method = RequestMethod.POST)
    public String getStaffs() throws Exception{
        JSONObject json = new JSONObject();
        List zcnStaffs = zcnStaffService.getZcnStaffs();//调用zcnStaffService的getZcnStaffs方法，获取员工列表
        json.put("data",zcnStaffs);
        return json.toJSONString();
    }

    @ResponseBody
    @RequestMapping(value = "/setStaff", method = RequestMethod.POST)
    public String setStaff(ZcnStaff zcnStaff) throws Exception{
        String str = zcnStaffService.setZcnStaff(zcnStaff);//调用zcnStaffService的setZcnStaff方法，传入zcnStaff参数，获取返回结果
        return str;
    }
}